import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo1 {
    public static void main(String[] args) {
        //创建一个最普通的线程池
        //能够根据任务的数目，自动进行线程扩容
        ExecutorService service = Executors.newCachedThreadPool();
        for (int i = 0; i < 10000; i++) {
            int id=i;
            service.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello "+ id+ ","+Thread.currentThread().getName());
                   // System.out.println("hello "+ i+ ","+Thread.currentThread().getName());
                    //i不能使用是因为线程捕获的问题
                }
            });

        }
        //创建固定数目的线程池
//        Executors.newFixedThreadPool(4);
//        //创建一个只包含单个线程的线程池
//        Executors.newSingleThreadExecutor();
//        //创建一个固定线程个数，但是任务延时执行的线程池
//        Executors.newScheduledThreadPool(4);
    }
}